package org.kunteng.yunac.modules.sys.utils;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 校验路由的Mac地址是否符合规范
 * <p/>
 * Created by ShiYun on 2015/11/18 0018.
 */
public class MacVerify {

    /**
     * Mac地址以空格,"-",":"分开
     */
//    private static String regx = "^([0-9a-fA-F]{2})(([/\\s:-][0-9a-fA-F]{2}){5})$";
    private static String regx = "^([0-9a-fA-F]{2})(([0-9a-fA-F]{2}){5})$";

    public static boolean isMac(List<String> list) {
        boolean flag = true;
        for (int i = 0; i < list.size(); i++) {
            String mac = list.get(i);
            flag = match(mac);
            if (flag == false) {
                System.out.println(mac+" 非法MAC地址");
                break;
            }
        }
        return flag;
    }

    public static boolean match(String mac) {
        Pattern pattern = Pattern.compile(regx);
        Matcher matcher = pattern.matcher(mac);
        return matcher.matches();
    }

    public static void main(String[] args) {
        String mac = "87:26:33:56:a8:f5";
        String mac2 = "shiyun";
        String mac3="12-01-6C-06-A6-29";
        String mac4="12016C06A629";
        System.out.println(match(mac));
        System.out.println(match(mac2));
        System.out.println(match(mac3));
        System.out.println(match(mac4));
    }
}
